//
//  MRCTest.m
//  Charles
//
//  Created by Leo on 2017/5/24.
//  Copyright © 2017年 charles. All rights reserved.
//

#import "MRCTest.h"

@interface MRCTest()

@property (nonatomic,assign)void(^block)();

@end

@implementation MRCTest

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUpView];
    }
    return self;
}

- (void)setUpView {
    
    UIButton * testButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    testButton.backgroundColor = [UIColor redColor];
    [testButton setTitle:@"MRC" forState:UIControlStateNormal];
    [self addSubview:testButton];

    [testButton makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(50);
        make.top.equalTo(100);
    }];
    [testButton addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)test {
    [self blockTest];
}

- (void)blockTest {
    int value = 10;
    void(^blockC)() = ^(){
        NSLog(@"只是一个block == %d",value);
    };
    NSLog(@"blockC is %@",blockC);
   
    /*MRC下此处需要copy
    _block = [blockC copy];
     */
    _block = blockC;

    NSLog(@"block is %@",_block);
}

- (void)buttonEvent:(UIButton *)sender {
    // 属性用assign 声明 这里会崩溃 因为blockTest里面声明的blcokC是一个临时变量，
    // 到button事件里面已经被释放了
    // 要想不崩溃 blcokTest 里面需要这么写：_block = [blockC copy];
    NSLog(@"%@",_block);
}

@end
